package com.dq.mail.interceptor;

import cn.hutool.json.JSONUtil;
import com.dq.mail.utils.R;
import com.dq.mail.utils.ThreadUserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: LoginInterceptor
 * @Description: 真正判断用户是否登录
 * @Author: app-backend-public_小强 (QQ:2680825683)
 * @Since: 2023/3/3 17:40
 */
public class LoginInterceptor implements HandlerInterceptor {
    /**
     * 拦截没有登录的用户相关URL
     *
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (ThreadUserHolder.getUser() == null) {
            response.setStatus(401);
            return false;
        }
        return true;
    }
}
